package com.ln.prac.base.xiaoao.dataStructure;

import java.util.Stack;

/**
 * 括号匹配问题，使用栈来实现
 *
 * @Author zhangj
 * @Date 2023/2/6 21:56
 */
public class Braket {

    public boolean isMatch(String str) {
        Stack<Character> stack = new Stack<>();
        for (char c : str.toCharArray()) {
            if(c == '{') {
                stack.push(c);
            } else {
                if(c == '}') {
                    if(stack.size() == 0) {
                        return false;
                    }
                    char item = stack.pop();
                    if(item != '{') {
                        return false;
                    }
                }
            }
        }
        return stack.size() == 0;
    }

    public static void main(String[] args) {
        String str = "{{{asdad}}}";
        System.out.println(new Braket().isMatch(str));
    }

}
